"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = __importDefault(require("fs-extra"));
var ss = require('socket.io-stream');
const Member_1 = require("../lib/Member");
const savePath = './file/';
function default_1(app) {
    const { socket, rooms, intercom } = app.locals;
    const { userId, username } = socket.handshake.query;
    ss(socket).on('file', (stream, fileConfig, member, cb) => {
        const { filename } = fileConfig;
        console.log('----file:save----', fileConfig, member, cb);
        stream.pipe(fs_extra_1.default.createWriteStream(`${savePath}/${filename}`));
        stream.on('end', () => {
            cb && cb();
        });
    });
    socket.on('file:save', function (file, member) {
        const _member = Member_1.Members.get(member.userId);
        console.log('----file:save----', file, member);
        fs_extra_1.default.outputFile(`./file/ttt-ttt.mp3`, file, { flag: 'a' }, () => {
            console.log('==== file:saved ====');
        });
        socket.to(_member.socketId).emit('file:save', { file: 'url path' });
    });
}
exports.default = default_1;
